//index.js
//获取应用实例
const app = getApp()
import * as news from '../../services/news'
import { parseTime } from '../../utils/util'
Page({
    data: {
        loadMoreText: '上拉加载更多',
        isIphoneX: false,
        newsList: []
    },
    onShow() {
        this.setData({
            isIphoneX: app.globalData.device && (app.globalData.device.indexOf('iPhone X') > -1)
        })
        // this.getNewsList()
    },
    // 
    getNewsList() {
        news.list().then(res => {
            let newData = res.page.records.map(item=>{
                const json = {}
                json.id = item.id
                json.title = item.title
                json.releaseTime = parseTime(item.releaseTime.replace(/-/g, '/'))
                return json
            })
            this.setData({
                newsList: newData
            })
        })
    },
    toNavigateToPages(e) {
        wx.navigateTo({
            url: e.currentTarget.dataset.url
        })
    },
    toSwitchTabPages(e){
        wx.switchTab({
            url: e.currentTarget.dataset.url
        });
    },
    toPages(e) {
        wx.navigateTo({
            url: `/pages/news/news?id=${e.currentTarget.dataset.id}`
        })
    },
   
})
